package shared

import (
	"errors"
	"fmt"
	"unicode/utf8"
)

// The shared validation funcion used by /ent/schema/.
func MaxRuneLength(maxLen int) func(s string) error {
	return func(s string) error {
		if utf8.RuneCountInString(s) > maxLen {
			return errors.New(fmt.Sprintf("value is more than the max length %v.", maxLen))
		}

		return nil
	}
}
